﻿using System;
using System.Collections.Generic;
using System.Text;
using static JustMathCore.CmdRule;

namespace JustMathCore
{
    public class CmdRule
    {
        public enum WriteType
        {
            Error,
            Mode,
            Info,
            Warning,
            Progress,
            Result,
        }
        public const string tagMode = "$m ";
        public const string tagInfo = "$i ";
        public const string tagWarning = "$w ";
        public const string tagError = "$e ";
        public const string tagProgress = "$p ";
        public const string tagResult = "$r ";
        public const string tagBegin = "<<=";
        public const string tagEnd = "=>>";
        public static void Write(WriteType type, string info)
        {
            switch (type)
            {
                case WriteType.Error:
                    Console.Write(tagError);
                    break;

                case WriteType.Mode:
                    Console.Write(tagMode);
                    break;
                case WriteType.Info:
                    Console.Write(tagInfo); 
                    break;
                case WriteType.Warning:
                    Console.Write(tagWarning);
                    break;
                case WriteType.Progress:
                    Console.Write(tagProgress);
                    break;
                case WriteType.Result:
                    Console.Write(tagResult);
                    break;
            }
            bool multiline = info.Contains("\n") | info.Contains("\r");
            if (multiline)
                Console.WriteLine(tagBegin);

            Console.WriteLine(info);

            if (multiline)
                Console.WriteLine(tagEnd);
        }
        public static byte ParseU8(string str)
        {
            if (str.IndexOf("0x") == 0)
            {
                return byte.Parse(str.Substring(2), System.Globalization.NumberStyles.HexNumber);
            }
            else
            {
                return byte.Parse(str);
            }
        }
        public static UInt16 ParseU16(string str)
        {
            if (str.IndexOf("0x") == 0)
            {
                return UInt16.Parse(str.Substring(2), System.Globalization.NumberStyles.HexNumber);
            }
            else
            {
                return UInt16.Parse(str);
            }
        }
        public static UInt32 ParseU32(string str)
        {
            if (str.IndexOf("0x") == 0)
            {
                return UInt32.Parse(str.Substring(2), System.Globalization.NumberStyles.HexNumber);
            }
            else
            {
                return UInt32.Parse(str);
            }
        }
        public static Int32 ParseI32(string str)
        {
            if (str.IndexOf("0x") == 0)
            {
                return Int32.Parse(str.Substring(2), System.Globalization.NumberStyles.HexNumber);
            }
            else
            {
                return Int32.Parse(str);
            }
        }
    }

}